package com.lineage.server.command.executor;

import com.lineage.server.datatables.CommandsTable;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.templates.L1Command;
import java.util.ArrayList;
import java.util.Iterator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class L1CommandHelp implements L1CommandExecutor {
  private static final Log _log = LogFactory.getLog(L1CommandHelp.class);
  
  public static L1CommandExecutor getInstance() {
    return new L1CommandHelp();
  }
  
  public void execute(L1PcInstance pc, String cmdName, String arg) {
    ArrayList<L1Command> list = new ArrayList<>();
    Iterator<L1Command> iterator = CommandsTable.get().getList().iterator();
    while (iterator.hasNext()) {
      L1Command command = iterator.next();
      if (pc == null) {
        if (!command.isSystem())
          continue; 
        list.add(command);
        continue;
      } 
      if (command.getLevel() > pc.getAccessLevel())
        continue; 
      list.add(command);
    } 
    Iterator<L1Command> iterator2 = list.iterator();
    while (iterator2.hasNext()) {
      L1Command command = iterator2.next();
      if (pc == null) {
        _log.info("可用命令: " + command.getName() + ": " + command.get_note());
        continue;
      } 
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(166, String.valueOf(String.valueOf(command.getName())) + ": " + command.get_note()));
    } 
    if (pc == null)
      _log.info("可用命令: c: 对游戏中玩家广播公告."); 
  }
}
